package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVo;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.convert.TeachplanConvert;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
//@RequestMapping("courseTeacher")
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;


    @GetMapping("courseTeacher/list/{courseId}")
    public List<CourseTeacherDTO> queryTeacherList(@PathVariable Long courseId) {
        Long companyId = SecurityUtil.getCompanyId();
        List<CourseTeacherDTO> teacherDTOList = courseTeacherService.queryTeacherList(courseId, companyId);
        return teacherDTOList;
    }

    @PostMapping("/courseTeacher")
    public CourseTeacherDTO createOrSetTeacher(@RequestBody CourseTeacherVo courseTeacherVo) {

        Long companyId = SecurityUtil.getCompanyId();

        CourseTeacherDTO teachplanDTO = CourseTeacherConvert.INSTANCE.vo2dto(courseTeacherVo);

        CourseTeacherDTO teacher = courseTeacherService.createOrSetTeacher(teachplanDTO,companyId);

        return teacher;
    }

    @DeleteMapping("/courseTeacher")
    public void romeCourseTeacher(@PathVariable Long courseBaseId, @PathVariable Long courseTeacherId) {

        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.romeCourseTeacher(courseBaseId,courseTeacherId,companyId);

    }
}
